package com.biodiv.miracle.event;

import com.biodiv.miracle.ioc.context.ApplicationContext;
import com.biodiv.miracle.support.utils.MiracleUtils;

import java.io.IOException;

/**
 * @Author: tianquan
 * @CreateTime: 2024-10-12  17:24
 * @Description: 打印事件
 */
public class PrintEvent extends EventObject {

    private static final String BANNER_PATH = "banner.path";

    private static final String ICON = """
                          _                         _       \s
                         (_)                       | |      \s
              _ __ ___    _   _ __    __ _    ___  | |   ___\s
             | '_ ` _ \\  | | | '__|  / _` |  / __| | |  / _ \\
             | | | | | | | | | |    | (_| | | (__  | | |  __/
             |_| |_| |_| |_| |_|     \\__,_|  \\___| |_|  \\___|
                                                            \s
                                 author: tianquan  version: 1.0\
            """;

    public PrintEvent(Object source) {
        super(source);
    }

    public String getIcon() {
        // 读取配置文件中
        String bannerPath = MiracleUtils.getPropertiesValue(BANNER_PATH);
        if (bannerPath == null) {
            return ICON;
        }
        // 读取配置文件中的banner路径
        ApplicationContext applicationContext = (ApplicationContext) getSource();
        String banner = applicationContext.getResourceAsString(bannerPath);
        return banner == null ? ICON : banner;
    }

}
